<?php
/**
 * Defines the Whale page type
 */
 
class WhalePage extends SecurePage {
   
}
 
class WhalePage_Controller extends SecurePage_Controller {

	function WhaleForm() {
		
		// Create fieldset containing fields
		$fields = new FieldSet(
			new TextField('Whale_ID', 'Whale ID'),
			new TextField('Gender'),
			new NumericField('Num_Calves', 'Number of Calves'),
			new NumericField('Pod_Size', 'Pod Size')
		);
 
		// Create action for form submission
		$actions = new FieldSet(new FormAction('submitWhale', 'Submit'));
	  
		// Set required fields
		$validator = new RequiredFields('Whale_ID');
 
	return new Form($this, 'WhaleForm', $fields, $actions, $validator);
	}

	function submitWhale($data, $form) {
		// Save form data into new Whale object and write to database
		$submission = new Whale();
		$form->saveInto($submission);
		$submission->write();
 
		Director::redirectBack();
	}
	
}
?>